package org.jeecg.modules.demo.property.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.demo.property.entity.ZnzfComplaint;
import org.jeecg.modules.demo.property.entity.ZnzfRepairment;
import org.jeecg.modules.demo.property.mapper.ZnzfRepairmentMapper;
import org.jeecg.modules.demo.property.service.IZnzfRepairmentService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysDepartMapper;
import org.jeecg.modules.system.mapper.SysUserMapper;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 报事报修
 * @Author: jeecg-boot
 * @Date:   2022-03-29
 * @Version: V1.0
 */
@Service
public class ZnzfRepairmentServiceImpl extends ServiceImpl<ZnzfRepairmentMapper, ZnzfRepairment> implements IZnzfRepairmentService {

    @Resource
    private ZnzfRepairmentMapper znzfRepairmentMapper;

    @Resource
    private SysUserMapper sysUserMapper;

    @Resource
    private SysDepartMapper sysDepartMapper;

    /**
     * 查找所有报修
     * @return
     */
    @Override
    public List<ZnzfRepairment> queryAllRepairment() {
        LambdaQueryWrapper<ZnzfRepairment> queryWrapper = new LambdaQueryWrapper<>();
        List<ZnzfRepairment> resList = new ArrayList<>();
        List<ZnzfRepairment> znzfRepairmentList = znzfRepairmentMapper.selectList(queryWrapper);
        for (int i = 0; i < znzfRepairmentList.size(); i++) {
            ZnzfRepairment znzfRepairment = znzfRepairmentList.get(i);
            SysUser sysUserSubmit = sysUserMapper.selectById(znzfRepairment.getSubmiter());
            SysDepart sysDepart = null;
            if (sysUserSubmit != null) {
                znzfRepairment.setUserName(sysUserSubmit.getRealname());
                sysDepart = sysDepartMapper.selectById(sysUserSubmit.getDepartIds());
            }
            if (sysDepart != null) {
                znzfRepairment.setDepartName(sysDepart.getDepartName());
                System.out.println();
            }
            if (znzfRepairment.getResponser() != null) {
                SysUser sysUserResponser = sysUserMapper.selectById(znzfRepairment.getResponser());
                if (sysUserResponser != null) {
                    znzfRepairment.setResponserName(sysUserResponser.getRealname());
                }
            }
            resList.add(znzfRepairment);
        }
        return resList;
    }
}
